package vg.services.data_base_manager.data.graph;

/**
 * This class realizes something attribute.
 * Warning: No thread safety.
 * @author tzolotuhin
 */

public class Attribute extends SystemAttributeItem implements Cloneable {
	// Main data
	private String name = null;
	private String value = null;
	private Class<?> type = null;
		
//=============================================================================
//-----------------Constructors------------------------------------------------
	public Attribute(String name, String value, Class<?> type) {
		this.name = name;
		this.value = value;
		this.type = type;
	}
	
	public Attribute(Attribute attribute) {
		super(attribute);
		this.name = attribute.name;
		this.value = attribute.value;
		this.type = attribute.type;
	}	

//=============================================================================
//-----------------PUBLIC METHODS----------------------------------------------	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getValue() {
		return value;
	}
	
	public void setValue(String value) {
		this.value = value;
	}
	
	public Class<?> getType() {
		return type;
	}
	
	public void setType(Class<?> type) {
		this.type = type;
	}
	
	public boolean isStringType() {
		return type == String.class;
	}

	public boolean isDoubleType() {
		return type == Double.class;
	}
	
	public boolean isFloatType() {
		return type == Float.class;
	}

	public boolean isIntegerType() {
		return type == Integer.class;
	}
	
	public boolean isBooleanType() {
		return type == Boolean.class;
	}
	
	public boolean isRealType() {
		return isDoubleType() || isFloatType() || isIntegerType();
	}
	
	@Override
	public int hashCode() {
		return getStorableId();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == this) return true;
		
		if (obj instanceof Attribute) {
			Attribute anotherAttr = ((Attribute)obj);
			if (getStorableId() >= 0 && getStorableId() == anotherAttr.getStorableId())
				return true;
			if (name == anotherAttr.name)
				return true;
			if (name != null && anotherAttr.name != null && 
				name.hashCode() == anotherAttr.name.hashCode() &&
				name.equals(anotherAttr.name)) return true;
		}		
		return false;
	}
	
	@Override
	public Attribute clone() {
		return new Attribute(this);
	}
}
